package com.example.aircraft.aircraft;

import android.media.MediaPlayer;

import com.example.aircraft.MyApplication;
import com.example.aircraft.R;
import com.example.aircraft.bullet.AbstractBullet;
import com.example.aircraft.bullet.BulletFactory;
import com.example.aircraft.bullet.LaunchBarrage;
import com.example.aircraft.prop.AbstractProp;
import com.example.aircraft.prop.PropFactory;

import java.util.LinkedList;
import java.util.List;

public class BossEnemy extends Enemy{

    private MediaPlayer bossBGM = MediaPlayer.create(MyApplication.getContext(), R.raw.bgm_1005);;
    public BossEnemy(int locationX, int locationY, int speedX, int speedY, int hp){
        super(locationX, locationY, speedX, speedY, hp);
        launchBarrage = new BossBarrage();
        if(MyApplication.isMusicOn()){
        bossBGM.start();
        bossBGM.setLooping(true);}

    }

    @Override
    public int getValue(){
        return 100;
    }
    @Override
    public List<AbstractProp> dropProp(){
        List<AbstractProp> res = new LinkedList<>();
        res.add(PropFactory.setProp("Redtea",this.getLocationX(),
                this.getLocationY()));
        return res;
    }
    @Override
    public void vanish(){
        isValid = false;
        if(bossBGM.isPlaying()){
            bossBGM.stop();
        }
        bossBGM.release();
        EnemyFactory.bossInsist = false;
    }

    /**
     * Boss机专用弹幕，作为类中类封装
     */
    private class BossBarrage implements LaunchBarrage {
        @Override
        public List<AbstractBullet> Launch(int locationX, int locationY, int power ,String Type){
            List<AbstractBullet> res = new LinkedList<>();
            int x = locationX;
            int y = locationY;
//            int speedx = speedX;
            AbstractBullet abstractBullet;
            for(int i=0; i<5; i++){
                // 子弹发射位置相对飞机位置向前偏移
                // 多个子弹横向分散
                Double direction = Double.valueOf(Math.pow(-1,i));
                int Direct = direction.intValue();

                abstractBullet = BulletFactory.dispatchBullet(Type ,x+ (i*2)*10, y+Direct*10, Direct*3, 10+Direct*5, power);
                res.add(abstractBullet);
            }
            return res;
        }
    }
    @Override
    public List<AbstractBullet> shoot() {
        return launchBarrage.Launch(locationX,locationY,hp/10,"Enemy");
    }
    @Override
    public void update(){
        this.decreaseHp(100);
    }
}

